const { resolve } = require("path");
const htmlWebpackPlugin = require("html-webpack-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin')

const isPro = process.env.NODE_ENV === 'production'

module.exports = {
  mode: isPro ? 'production' : "development",
  entry: resolve(__dirname, "./src/main.js"),
  output: {
    path: resolve(__dirname, "build"),
    filename: "[chunkhash].js",
  },
  devtool: "source-map",
  resolveLoader: {
    modules: ["node_modules", resolve(__dirname, "loader")],
  },
  module: {
    rules: [
      // { test: /\.css$/, loader: "style-loader!css-loader" },
      // { test: /\.scss$/, loader: "style!css!sass" },
      {
        test: /\.js$/,
        exclude: /node_modules/, // 排除node_modules中的代码
        use: [
          {
            loader: "babel-loader",
          },
        ],
      },
      {
        test: /\.vue$/,
        use: [
          {
            loader: "vue-loader",
            options: {
              compilerOptions: {
                preserveWhitespace: false,
              },
            },
          },
        ],
      },
      {
        test: /\.md$/,
        use: [
          {
            loader: "vue-loader",
            options: {
              compilerOptions: {
                preserveWhitespace: false,
              },
            },
          },
          {
            loader: "md-loader",
          }
        ]
      },
      {
        test: /\.tpl/,
        use: [
          "babel-loader",
          {
            loader: "tpl-loader",
            options: {
              log: true,
            },
          },
        ],
      },
    ],
  },
  plugins: [
    new htmlWebpackPlugin({
      template: resolve(__dirname, "./public/index.html"),
    }),
    new VueLoaderPlugin()
  ],
  devServer: {
    port: 3333,
  },
};
